/*
 * MouseListener.java
 */

package org.owasp.scrubbr.db.report;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Date;
import javax.swing.JButton;
import javax.swing.JTable;

public class MouseClickListener implements MouseListener {
    
    private JButton whyFlagged;
    private double lastClicked;
    
    /** Creates a new instance of MouseListener */
    public MouseClickListener(JTable table, JButton whyFlagged) {
        table.addMouseListener(this);
        this.whyFlagged = whyFlagged;
    }

    public void mouseClicked(MouseEvent mouseEvent) {

        if ( mouseEvent.getClickCount() == 2) { /* double click */
            
            double now = new Date().getTime();
            
            if ( (now - lastClicked) > 30 ) {
                whyFlagged.doClick();    
            }   
            
            lastClicked = now;
            
        }
    }

    public void mousePressed(MouseEvent mouseEvent) {
    }

    public void mouseReleased(MouseEvent mouseEvent) {
    }

    public void mouseEntered(MouseEvent mouseEvent) {
    }

    public void mouseExited(MouseEvent mouseEvent) {
    }
    
}
